module crampcnt
	(clock, resetn, sclr, cnten, gain, offset, satlevel, Q);
input 			clock, resetn;
input			sclr, cnten;
input	[3:0]	gain;
input	[13:0]	offset;
input	[9:0]	satlevel;
output	[13:0]	Q;

wire	[9:0]	q_rampcnt;
wire	[13:0]	Q_offsetfree;
wire	[13:0]	Q_temp;
wire			saturated;

lpm_rampcnt		lpm_rampcnt_inst
				(.clock(clock), .cnt_en(cnten), .sset(sclr), .aset(~resetn),
				 .q(q_rampcnt));
lpm_rampmult	lpm_rampmult_inst
				(.dataa(q_rampcnt), .datab(gain), .result(Q_offsetfree));
lpm_rampadd		lpm_rampadd_inst
				(.dataa(Q_offsetfree), .datab(offset), .result(Q_temp));
lpm_rampcomp	lpm_rampcomp_inst
				(.dataa(q_rampcnt), .datab(satlevel), .ageb(), .aleb(saturated));

assign			Q = (saturated)? 14'b0 : Q_temp;

endmodule